//
//  NewsFocusImageCell.m
//  suRead
//
//  Created by lidi on 2018/6/3.
//  Copyright © 2018年 bao. All rights reserved.
//

#import "NewsFocusImageCell.h"
#import "UIImageView+WebCache.h"
#import "M_News.h"
#import "M_SpecialNews.h"
#import "Masonry.h"

#import "SDCycleScrollView.h"

@interface NewsFocusImageCell()<SDCycleScrollViewDelegate>
@property (nonatomic,weak)IBOutlet SDCycleScrollView *focusScrollView;
@end

@implementation NewsFocusImageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


- (void)setNewsDatas:(NSArray *)newsDatas
{
    _newsDatas = newsDatas;
    
    NSInteger focusCount = [newsDatas count];
    if (!focusCount) {
        return;
    }
    
    NSMutableArray *focusNews_ = [NSMutableArray array];
    
    for (int i = 0; i < [_newsDatas count]; i ++) {
        NSString *imageURL;
        if ([[_newsDatas objectAtIndex:i] isKindOfClass:[M_SpecialNews class]]) {
            M_SpecialNews *news = [_newsDatas objectAtIndex:i];
            imageURL = news.f_banner;
        } else {
            M_News *news = [_newsDatas objectAtIndex:i];
            imageURL = news.f_thumbnail;
        }
        [focusNews_ addObject:imageURL];
    }
    
    
    self.focusScrollView.imageURLStringsGroup = focusNews_;
    self.focusScrollView.autoScrollTimeInterval = 5.0f;
    self.focusScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
    self.focusScrollView.delegate = self;
    self.focusScrollView.titlesGroup = nil;
    self.focusScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    self.focusScrollView.currentPageDotColor = [UIColor yellowColor]; // 自定义分页控件小圆标颜色
    self.focusScrollView.placeholderImage = [UIImage imageNamed:@"placeholder"];
}

#pragma mark - SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if (self.focusTapAtIndex) {
        self.focusTapAtIndex([self.newsDatas objectAtIndex:index]);
    }
}

@end
